Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathItem as parameter to avoid race conditions #87

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

emilien-puget
Copy link
Contributor

@emilien-puget emilien-puget commented Jul 8, 2024

A race condition was caused by saving some values to the validator struct


=== RUN   TestNewValidator_concurrent
==================
WARNING: DATA RACE
Write at 0x00c000190018 by goroutine 107:
  github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequest()
      /home/emilien/workspace/go/libopenapi-validator/validator.go:173 +0x10d
  github.com/pb33f/libopenapi-validator.TestNewValidator_concurrent.func1()
      /home/emilien/workspace/go/libopenapi-validator/validator_test.go:109 +0x2d4

Previous read at 0x00c000190018 by goroutine 108:
  github.com/pb33f/libopenapi-validator.(*validator).ValidateHttpRequest()
      /home/emilien/workspace/go/libopenapi-validator/validator.go:167 +0x54
  github.com/pb33f/libopenapi-validator.TestNewValidator_concurrent.func2()
      /home/emilien/workspace/go/libopenapi-validator/validator_test.go:121 +0x2d4

Goroutine 107 (running) created at:
  github.com/pb33f/libopenapi-validator.TestNewValidator_concurrent()
      /home/emilien/workspace/go/libopenapi-validator/validator_test.go:103 +0x397
  testing.tRunner()
      /home/emilien/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /home/emilien/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1742 +0x44

Goroutine 108 (running) created at:
  github.com/pb33f/libopenapi-validator.TestNewValidator_concurrent()
      /home/emilien/workspace/go/libopenapi-validator/validator_test.go:115 +0x4f3
  testing.tRunner()
      /home/emilien/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /home/emilien/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1742 +0x44
==================

this is a breaking change because SetPathItem method does not exists anymore, you have instead a function that can accept a pathItem and pathValue

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.77%. Comparing base (bc63c2f) to head (211eac0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   99.72%   99.77%   +0.05%     
==========================================
  Files          19       19              
  Lines        1812     1813       +1     
==========================================
+ Hits         1807     1809       +2     
+ Misses          5        4       -1     
Flag Coverage Δ
unittests 99.77% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emilien-puget emilien-puget force-pushed the pathitem-as-param branch 6 times, most recently from 6a1de27 to b337b65 Compare July 9, 2024 08:13
@emilien-puget
Copy link
Contributor Author

@daveshanley wdyt ?

Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup. Definitely a breaking change, but a good one!

@daveshanley daveshanley merged commit 696235e into pb33f:main Jul 9, 2024
3 checks passed
@emilien-puget emilien-puget deleted the pathitem-as-param branch July 10, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants